﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
namespace KabiManagementWeb.Controllers
{
    public class CustomerTypeController : Controller
    {

        KBManagementDataContext context = new KBManagementDataContext();
        //
        // GET: /CustomerType/

        public ActionResult Index()
        {

            return View(context.Customer_Types);
        }

        //
        // GET: /CustomerType/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /CustomerType/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /CustomerType/Create

        [HttpPost]
        public ActionResult Create(Customer_Type customerType)
        {
            try
            {
                context.Customer_Types.InsertOnSubmit(customerType);
                context.SubmitChanges();
                return RedirectToAction("Index");

            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /CustomerType/Edit/5

        public ActionResult Edit(string id)
        {
            var type = context.Customer_Types.Single(x => x.ID.Equals(id));
            return View(type);
        }

        //
        // POST: /CustomerType/Edit/5

        [HttpPost]
        public ActionResult Edit(string id, Customer_Type custype)
        {
            try
            {
                var type = context.Customer_Types.Single(x => x.ID.Equals(id));
                type.NormsMoney = custype.NormsMoney;
                type.Ct_Name = custype.Ct_Name;
                type.Rate = custype.Rate;
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /CustomerType/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /CustomerType/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
